<?php

/**
 * @author    1054229380@qq.com
 * @since    2017-7-3
 * @desc 分页类
 * */
class page
{

    /**
     * 数据分页
     * @param @pageCount    总页数
     * @param @currentPage  当前页
     * @param @totalRows    总记录数
     * @param @pageSize     单页数量
     * @param @linkStr      自定义链接
     * @param @pageStyleStr 显示风格,1
     * @return string
     * */
    public static function pageList($pageCount, $currentPage, $totalRows, $pageSize, $linkStr, $pageStyle = '1')
    {
        if ($currentPage == "") {
            $currentPage = 1;
        }
        $pages_view = 9;
        $pageend = $str = null;
        if ($currentPage <= $pages_view - 5) {
            $add_p1 = $currentPage - 1;
            $add_p2 = $pages_view - $currentPage + 1;
            if (($currentPage + $add_p2) > $pageCount) {
                $add_p2 = $pageCount - $currentPage;
            }
        } elseif ($currentPage > $pageCount - $pages_view + 5) {
            $add_p1 = $currentPage - ($pageCount - $pages_view) - 1;
            $add_p2 = $pageCount - $currentPage;
        } else {
            $add_p1 = 4;
            $add_p2 = 4;
        }

        for ($i = $currentPage - $add_p1; $i <= $currentPage + $add_p2; $i++) {
            $x = substr($linkStr, 0, 1);
            $s_lm = substr($linkStr, 1, 1);
            if ($x == "///") {//是HTML
                $url1 = "{$linkStr}1.html"; //第一页链接
                $url2 = "{$linkStr}{$pageCount}.html"; //最后一页链接
                $url = "{$linkStr}{$i}.html"; //页码链接
            } else {
                $url1 = "{$linkStr}1{$pageend}"; //第一页链接
                $url2 = "{$linkStr}{$pageCount}{$pageend}"; //最后一页链接
                $url = "{$linkStr}{$i}{$pageend}"; //页码链接
            }

            if ($i == $currentPage) {
                $str = $str . "<span class='current'>{$i}</span>";
            } else {
                if ($i > 0) {
                    $str = $str . "<a href='{$url}'>{$i}</a>";
                }
            }
        }
        if ($totalRows == "0") {
            $str = "";
        } else {
            $str = "<span class='pagelist_a'><span style='margin-right:10px;'>共{$totalRows}条记录,{$pageCount}页,{$pageSize}条/页</span><a href='{$url1}' title='第一页'><</a>{$str}<a href='{$url2}' title='最后一页'>></a></span>";
        }
        return $str;
    }

}

?>